﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;

namespace AimGameLibrary.AimGame.Game3D.Camera
{
    public class Camera3D : BaseGame3D
    { 
        Vector3 direction;
        public Vector3 DirectioN { get { return direction; } set { direction = value; } }

        float fieldOfView;
        public float FieldOfVieW { get { return fieldOfView; } set { fieldOfView = value; } }

        float aspectRatio;
        public float AspectRatiO { get { return aspectRatio; } set { aspectRatio = value; } }

        float near;
        public float NeaR { get { return near; } set { near = value; } }

        float far;
        public float FaR { get { return far; } set { far = value; } }

        Matrix viewMatrix;
        public Matrix ViewMatrix { get { return viewMatrix; } set { viewMatrix = value; } }

        Matrix projectionMatrix;
        public Matrix ProjectionMatriX { get { return projectionMatrix; } set { projectionMatrix = value; } }

        protected float anglePitch;
        protected float maxPitch;
        protected float minPitch;

        public Camera3D(ScreenManager.ScreenManagers screenmanager)
        {
            direction = Vector3.Forward;
            fieldOfView = MathHelper.PiOver4;

            aspectRatio = (float)screenmanager.GraphicsDevice.Viewport.Width / (float)screenmanager.GraphicsDevice.Viewport.Height;
            //aspectRatio = 16.0f / 9.0f;
            near = 0.2f;
            far = 300;
            maxPitch = MathHelper.Pi / 3.0f;
            minPitch = -MathHelper.Pi / 3.0f;
            anglePitch = 0;
        }

        public override void UpdateMatrix()
        {
            base.UpdateMatrix();

            ViewMatrix = Matrix.CreateLookAt(PositioN, PositioN + DirectioN, Vector3.Up);
            ProjectionMatriX = Matrix.CreatePerspectiveFieldOfView(FieldOfVieW, AspectRatiO, NeaR, FaR);
        }
    }
}
